<%@ page import="com.h.heal.entity.Admin" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Heal后台用户管理编辑</title>
    <jsp:include page="../../common_css.jsp"/>

    <style>
        .form-control {
            width: 30%;
        }
    </style>
</head>
<body style="background: linear-gradient(to top right, #a1ffce 0%, #faffd1 100%);">
<div class="container-scroller">
    <!-- partial:partials/_navbar.html -->
    <jsp:include page="../../top.jsp"/>

    <!-- partial -->
    <div class="container-fluid page-body-wrapper">
        <!-- partial:partials/_sidebar.html -->
        <jsp:include page="../../left.jsp"/>
        <!-- partial -->
        <div class="main-panel">
            <div class="row">
                <div class="col-md-12 stretch-card">
                    <div class="card"style="background: rgba(255,255,255,0);
    border: none;">
                        <div class="card-body">

                            <div class="table-responsive" align="center">


                                <form id="frm" class="form-signin">
<%--                                    <img class="mb-4"--%>
<%--                                         src="${pageContext.request.contextPath}/style/images/Logo with Inverted Palette - No Background.png"--%>
<%--                                         alt="" width="300" height="300">--%>
                                    <h1 class="h3 mb-3 font-weight-normal">编辑用户信息</h1>
                                    <label for="input_user_uid" class="sr-only">用户id</label>
                                    <%--              获得用户编号                          value="${user.user_uid}--%>
                                    <input type="text" id="input_user_uid" name="user_uid" class="form-control"
                                           value="${user.user_uid}" placeholder="用户id" user_pwd>

                                    <label for="input_user_name" class="sr-only">用户名</label>
                                    <input type="text" id="input_user_name" name="user_name" class="form-control"
                                           value="${user.user_name}" placeholder="用户名">

                                    <label for="input_user_pwd" class="sr-only">用户密码</label>
                                    <input type="text" id="input_user_pwd" name="user_pwd"
                                           class="form-control" value="${user.user_pwd}" placeholder="用户密码">

                                    <label for="input_user_pwd_check" class="sr-only">确认密码</label>
                                    <input type="text" id="input_user_pwd_check" name="user_pwd_check"
                                           class="form-control" value="${user.user_pwd}" placeholder="确认密码">

                                    <label for="input_user_vip" class="sr-only">用户等级</label>
                                    <input type="text" id="input_user_vip" name="user_vip"
                                           class="form-control" value="${user.user_vip}" placeholder="用户等级">


                                    <label for="input_user_state" class="sr-only">用户状态</label>
                                    <input type="text" id="input_user_state" name="user_state"
                                           class="form-control" value="${user.user_state}" placeholder="用户状态">


                                    <button class="btn btn-lg btn-primary btn-block" type="button" onclick="doEdit()"
                                            style="width: 30%">编辑
                                    </button>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <jsp:include page="../../footer.jsp"/>
    </div>
    <!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<jsp:include page="../../common_js.jsp"/>
</body>

</html>

<script>
    function doEdit() {
        //推荐前端js验证字段
        var userName = $("#input_user_name").val();
        var pwd = $("#input_user_pwd").val();
        var pwd_check = $("#input_user_pwd_check").val();
        if (userName == null || userName == "" || pwd == null || pwd == "" || pwd_check == null || pwd_check == "") {
            alert("账号或密码不能为空");
        } else {
            //手机号正则式
            // var reguserName = /^(13[0-9]|14[01456879]|15[0-35-9] |16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;

            var regpwd = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/
            // if (!reguserName.test(userName)) {
            //     alert("请输入正确的手机号");
            // }
            if (!regpwd.test(pwd)) {
                alert("密码输入不正确，应包括大小写和数字且长度不少于8位");
            } else {
                if (pwd == pwd_check) {
                    $.ajax(
                        {
                            type: "post",
                            url: "/user/doEdit",
                            data: $("#frm").serialize(),
                            async: false,  //使用ajax同步提交数据
                            success: function (response) {
                                if (response == "ok") {
                                    // alert("用户编辑成功,1秒后跳转到用户列表");
                                    setTimeout(window.location.href = "/user/main", 500);
                                } else {
                                    alert("编辑失败，请联系管理员....");
                                }
                            }
                        }
                    );
                } else {
                    alert("两次密码输入不同，请检查");
                }
            }
        }
    }
</script>

